import { request } from 'umi';
import { OfficeTreeResponse,getOfficeParams,GetOfficeListResponse,OfficeInfoSaveRequestParams,GetOfficeDetailsResponse,OfficeDeleteRequestParams} from './data'

//部门查询列表
export async function queryOfficeList(options?: {
    [key: string]: any;
}){
    return  request<AircasKB.ResponseType<GetOfficeListResponse[]>>(
        `/aircaskb/sys/office/list`,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            ...(options || {}),
        });
}

//获取系统部门树
export async function getSystemOfficeTreeData(options?: {
    [key: string]: any;
}){
    return  request<AircasKB.ResponseType<OfficeTreeResponse[]>>(
        `/aircaskb/sys/office/officeSimpleTree`,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            ...(options || {}),
        });
}

// 查看角色拥有的部门的列表
export async function getOfficeTreeByOffice(
    body: getOfficeParams, 
    options?: { [key: string]: any }){
    const { roleId } = body;
    return  request<AircasKB.ResponseType<OfficeTreeResponse[]>>(
        `/aircaskb/sys/office/${roleId}`,
        {
            method: 'GET',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            ...(options || {}),
        });
}

// 保存角色信息
export async function OfficeInfoSaveRequest(body:OfficeInfoSaveRequestParams, options?: {[key: string]: any}){
    return request(
        `/aircaskb/sys/role/save`, {
            method: 'POST',
            data:body,
            ...(options || {}),
        });
}

// 删除角色
export async function DeleteOfficeRequest(
    body: OfficeDeleteRequestParams, 
    options?: { [key: string]: any }){
    const { ids } = body;
    return request<AircasKB.ResponseType<GetOfficeDetailsResponse>>(
        `/aircaskb/sys/role/delete/${ids}`,
        {   
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded',
            },
            method: 'GET',
            ...(options || {}),
        },
    );
}